home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
archiver
/
lha211sr.zip
/
LHASRC.EXE
/
SFX_.ASM
< prev
next >
Wrap
Assembly Source File
|
1991-03-03
|
24KB
|
1,303 lines
;***********************************************
; sfx_.asm -- self-extract module
;***********************************************
page 0, 128
include amscls.inc
$_init GEN
_TEXT segment byte public 'CODE'
_TEXT ends
DGROUP group _BSS
assume cs:_TEXT, ds:DGROUP
CRC16 equ 0a001h
BufSiz equ 04000h
NC = (200h - 2)
NP = 14
NT = 19
NPT = 080h
CBIT = 9
PBIT = 4
TBIT = 5
DSIZ = 2000h
DSIZ2 = DSIZ * 2
LzHead struc
HeadSiz db ?
HeadChk db ?
HeadID db 3 dup (?)
Method db ?
db ?
PacSiz dw 2 dup (?)
OrgSiz dw 2 dup (?)
FTime dw ?
FDate dw ?
FAttr dw ?
FnLen db ?
Fname db 80h dup (?)
LzHead ends
_BSS segment para public 'BSS'
public crctbl
public cpyhdr, infile, outfile
public inpptr, inpbuf, text_
public curcrc, orgcrc
public myname
public pathname, fnnext, swchar
public blocksize_
text_ db DSIZ2 dup (?)
inpbuf db BufSiz dup (?)
crctbl dw 100h dup (?)
cpyhdr LzHead 1 dup (<?>)
inpptr dw 1 dup (?)
infile dw 1 dup (?)
outfile dw 1 dup (?)
orgcrc dw 1 dup (?)
curcrc dw 1 dup (?)
blocksize_ dw 1 dup (?)
len_cnt dw 17 dup (?)
start dw 17 dup (?)
weight dw 17 dup (?)
public len_cnt
public start
public weight
left_ dw 2 * NC - 1 dup (?)
right_ dw 2 * NC - 1 dup (?)
c_table_ dw 4096 dup (?)
pt_table_ dw 256 dup (?)
c_len_ db NC dup (?)
pt_len_ db NPT dup (?)
public left_
public right_
public c_table_
public pt_table_
public c_len_
public pt_len_
bitbuf_ dw 1 dup (?)
subbitbuf_ db 1 dup (?)
bitcount_ db 1 dup (?)
myname db 80h dup (?)
pathname db 80h dup (?)
fnnext dw 1 dup (?)
fnptr dw 1 dup (?)
swchar db 1 dup (?)
endBBS label byte
_BSS ends
_TEXT segment byte public 'CODE'
assume cs:_TEXT
org 0100h
public start, main
public BSSseg
public #cright, crlf, space
public absent, #myself, broken, extend
public #subver
top:
jmp main
BSSseg = (#endofcode - top + 10fh) / 10h
mes_yn equ space - 1
space db ' ', 0
#cright db "LHA's SFX 2.11"
#subver db "L (c) Yoshi, 1991"
crlf db 13, 10, 0
absent db 'Rename to '
#myself db 'FILENAME.EXT', 0
overwt db 'Overwrite ', 0
yesno db '[Y/N] ', 0
broken db 'Broken file ', 0
write db 'Write', 0
header db 'Header', 0
crcmes db 'CRC'
error db ' Error', 0
auto db 1, '!'
autoflg db '.' shr 1
db 'BAT'
extend db 0ffh
attrib db 0
envseg = 002ch
cmdcnt = 0080h
cmdline = 0081h
;-----------------------------------------------
; âüâCâôâïü[â`âô
;-----------------------------------------------
main:
cld
mov sp, offset top
mov ax, cs
add ax, BSSseg
mov es, ax
assume es:DGROUP
call @getopt
public #getopt
#getopt:
mov bx, offset #cright
call mesout
push es
pop ds
assume ds:DGROUP
;-----------------------------------------------
; Get my name
;-----------------------------------------------
mov ah, 30h
int 21h ; get DOS ver.
mov bx, ax
push ds
$_if <cmp al, 3>, AE ; if DOS ver. >= 3.00
mov es, ss:[envseg]
xor ax, ax
mov di, ax
mov cx, -1
$_do
repne scasb
scasb
$_until , E
inc ax
scasw
push es
pop ds
mov dx, di
$_if , E
call openme
$_endif
$_endif
brknenv:
push cs
pop ds
mov dx, offset #myself
call openme
$_if <cmp bl, 2>, E ; if DOS ver. = 2
mov ax, ss:[0002h] ; get pathname from trash
sub ax, 38h ; of command.com
mov ds, ax
mov dx, 0009h
call openme
$_endif
mov bx, offset absent
jmp errout1
openme:
mov ax, 3d00h
int 21h ; Open Myself
$_if , C
ret
$_endif
pop cx ; pop old ip
pop ds
mov infile, ax
mov bx, ax
xor cx, cx
ifndef COM
exehdr = 20h
else
exehdr = 0h
endif
mov dx, (#endofcode - top) + exehdr
public #seeksize
#seeksize:
mov ax, 4200h
int 21h ; Move a File Pointer
$_if , C
brokenerr:
mov bx, offset broken ; Broken file
jmp errout
$_endif
push ds
pop es
;---------------------------------------
; make CRC table
;---------------------------------------
mov di, offset crctbl
xor dx, dx
$_do
mov ax, dx
mov cx, 8
$_do
$_if <shr ax, 1>, C
xor ax, CRC16
$_endif
$_until <LOOP>
stosw
$_until <inc dl>, Z
;---------------------------------------
public mainloop
mainloop:
$_while <TRUE>
call crlfout
; Get Header ---------------------------
mov si, offset DGROUP:cpyhdr.HeadSiz
mov dx, si
mov cx, 1
mov [si], ch
mov bx, infile
mov ah, 3fh
int 21h ; Read header size
dec cx ; cx = 0
add cl, [si]
$_if , Z
jmp exit
$_endif
inc dx
inc si
inc cx
mov ah, 3fh
int 21h ; Read header
; Test Header Sum ----------------------
lodsb
push si ; cpyhdr.HeadID
dec cx
dec si
$_do
inc si
sub al, [si]
$_until <LOOP>
jne errhdr
pop si
; Test Header ID -----------------------
lodsw
$_if <cmp ax, 'l-'>, NE, OR
lodsw
xchg al, ah
sub ax, 'h0'
mov bp, ax ; bp = method
$_c , NZ, AND
$_c <sub ax, 0004h>, NE, AND
$_c <dec ax> , NE, OR
lodsb
$_c <sub al, '-'>, NZ
errhdr:
mov bx, offset header
jmp errout
$_endif
; Get original CRC ---------------------
mov bx, offset DGROUP:cpyhdr.Fname
mov dx, bx
mov cx, [bx - 1]
add bl, cl ; doesn't carry up
xchg ax, [bx] ; ax = 0, [bx] = CRC
mov orgcrc, ax
; Test Special File ? ------------------
mov fnptr, dx
cmp cx, 2101h ; 01h, '!'
$_if , E
mov ax, 1
jmp mn7
$_endif
call @extended
public #extended
#extended:
; Display File name --------------------
mov word ptr [bx], 0 * 256 + ' '
mov bx, dx
call disp ; output file name
mov byte ptr [bx - 1], 0
jcxz mn9 ; !.BAT ?
; Check Existence of File --------------
mov ax, 4300h ; get file attr
int 21h ; (for MS-DOS 3.3)
jc mn1
; Overwrite ? --------------------------
mov bx, offset overwt ; prompt
call mesout
call getyn
je mn1
; Skip to next File --------------------
mov dx, DGROUP:cpyhdr.PacSiz ; skip file
mov cx, DGROUP:cpyhdr.PacSiz + 2
mov bx, infile
mov ax, 4201h
int 21h ; Move a File Pointer
jmp mn6
mn9:
mov cs:autoflg, 0dh
; Create a New File --------------------
mn1:
mov cx, 0020h
mov ah, 3ch
int 21h ; Create a File
$_if , C
jmp errwrite
$_endif
; Decode -------------------------------
mn7:
mov outfile, ax
xor ax, ax
mov curcrc, ax
dec ax
mov inpptr, ax
push dx
$_if <or bp, bp>, NZ
call decode
$_else
call copyall
$_endif
pop si
; Set Time-Stamp -----------------------
mov bx, outfile
cmp bx, 1 ; file '!' ?
je mn8
mov dx, DGROUP:cpyhdr.FDate
mov cx, DGROUP:cpyhdr.FTime
mov ax, 5701h ; set date
int 21h
call close
; Check CRC ----------------------------
mov ax, curcrc
cmp ax, orgcrc
jne errcrc
call @setattr
public #setattr
#setattr:
jmp mn6
mn8:
call getyn
jne exit1
mn6:
$_enddo
mov bx, infile
call close
public exit
exit:
call @autoexec
public #autoexec
#autoexec:
exit1:
xor al, al
exit2:
mov ah, 4ch
int 21h
;-----------------------------------------------
; âGâëü[Åêù¥
;-----------------------------------------------
public errhdr, errwrite, errout
errcrc:
call unlink
mov bx, offset crcmes
jmp short errout1
errwrite:
mov bx, outfile
call close
call unlink
mov bx, offset write
errout:
call mesout
mov bx, offset error
errout1:
call mesout
mov al, 1
jmp exit2